home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / comm2 / ampop118.lha / AmiPOP118 / source / pop.c < prev    next >
C/C++ Source or Header  |  1995-09-13  |  11KB  |  443 lines

  1. #include "pop.h"
  2.  
  3. struct Screen         *Scr = NULL;
  4. APTR                   VisualInfo = NULL;
  5. struct Window         *Project0Wnd = NULL;
  6. struct Gadget         *Project0GList = NULL;
  7. struct Menu           *Project0Menus = NULL;
  8. struct IntuiMessage    Project0Msg;
  9. struct Gadget         *Project0Gadgets[9];
  10. UWORD                  Project0Width = 418;
  11. UWORD                  Project0Height = 69;
  12. UBYTE                    *Project0Wdt = (UBYTE *)VersionID + 6;
  13. struct TextAttr       *Font, Attr;
  14. UWORD                  FontX, FontY;
  15. UWORD                  OffX, OffY;
  16.  
  17. ULONG __saveds __asm hidepass( register __a0 struct Hook*, register __a2 struct SGWork* ,register __a1 ULONG* );
  18.  
  19. struct Hook hookentry =
  20. {
  21.     {0},
  22.     hidepass,
  23.     0,
  24.     0,
  25. };
  26.  
  27. struct NewMenu Project0NewMenu[] = {
  28.     NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
  29.     NM_ITEM, (STRPTR)"Hide", (STRPTR)"H", 0, 0L, (APTR)Project0MENU_HIDE,
  30.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  31.     NM_ITEM, (STRPTR)"About...", NULL, 0, 0L, (APTR)Project0MENU_ABOUT,
  32.     NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, (APTR)Project0MENU_QUIT,
  33.     NM_END, NULL, NULL, 0, 0L, NULL };
  34.  
  35. static UWORD ComputeX( UWORD value )
  36. {
  37.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  38. }
  39.  
  40. static UWORD ComputeY( UWORD value )
  41. {
  42.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  43. }
  44.  
  45. static void ComputeFont( UWORD width, UWORD height )
  46. {
  47.     Font = &Attr;
  48.     Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
  49.     Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
  50.     FontX = Scr->RastPort.Font->tf_XSize;
  51.  
  52.     OffX = Scr->WBorLeft;
  53.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  54.  
  55.     if ( width && height ) {
  56.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  57.             goto UseTopaz;
  58.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  59.             goto UseTopaz;
  60.     }
  61.     return;
  62.  
  63. UseTopaz:
  64.     Font->ta_Name = (STRPTR)"topaz.font";
  65.     FontX = FontY = Font->ta_YSize = 8;
  66. }
  67.  
  68. int SetupScreen( void )
  69. {
  70.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  71.     {
  72.         if ( ! (Scr = LockPubScreen( NULL )))
  73.         {
  74.             return( 1L );
  75.         }
  76.     }
  77.  
  78.     ComputeFont( 0, 0 );
  79.  
  80.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  81.         return( 2L );
  82.  
  83.     return( 0L );
  84. }
  85.  
  86. void CloseDownScreen( void )
  87. {
  88.     if ( VisualInfo ) {
  89.         FreeVisualInfo( VisualInfo );
  90.         VisualInfo = NULL;
  91.     }
  92.  
  93.     if ( Scr        ) {
  94.         UnlockPubScreen( NULL, Scr );
  95.         Scr = NULL;
  96.     }
  97. }
  98.  
  99. void Project0Render( void )
  100. {
  101.     ComputeFont( Project0Width, Project0Height );
  102.  
  103.     DrawBevelBox( Project0Wnd->RPort, OffX + ComputeX( 0 ),
  104.                     OffY + ComputeY( 50 ),
  105.                     ComputeX( 417 ),
  106.                     ComputeY( 18 ),
  107.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  108. }
  109.  
  110. int HandleProject0IDCMP( void )
  111. {
  112.     struct IntuiMessage    *m;
  113.     struct MenuItem        *n;
  114.     int            (*func)( void );
  115.     BOOL            running = TRUE;
  116.  
  117.     while( (Project0Wnd) && (m = GT_GetIMsg( Project0Wnd->UserPort ) ) ) {
  118.  
  119.         CopyMem(( char * )m, ( char * )&Project0Msg, (long)sizeof( struct IntuiMessage ));
  120.  
  121.         GT_ReplyIMsg( m );
  122.  
  123.         switch ( Project0Msg.Class ) {
  124.  
  125.             case    IDCMP_REFRESHWINDOW:
  126.                 GT_BeginRefresh( Project0Wnd );
  127.                 Project0Render();
  128.                 GT_EndRefresh( Project0Wnd, TRUE );
  129.                 break;
  130.  
  131.             case    IDCMP_CLOSEWINDOW:
  132.                 running = Project0CloseWindow();
  133.                 break;
  134.  
  135.             case    IDCMP_VANILLAKEY:
  136.                 Project0VanillaKey();
  137.                 break;
  138.  
  139.             case    IDCMP_CHANGEWINDOW:
  140.                 Project0ChangeWindow();
  141.                 break;
  142.  
  143.             case    IDCMP_GADGETUP:
  144.                 func = ( int (*) (void ) )(( struct Gadget * )Project0Msg.IAddress )->UserData;
  145.                 func();
  146.                 break;
  147.  
  148.             case    IDCMP_MENUPICK:
  149.                 while ( (Project0Msg.Code != MENUNULL) && (Project0Wnd) )
  150.                 {
  151.                     n = ItemAddress( Project0Menus, Project0Msg.Code );
  152.                     func = (int (*) (void) )(GTMENUITEM_USERDATA(n));
  153.                     running= func();
  154.                     Project0Msg.Code = n->NextSelect;
  155.                 }
  156.                 break;
  157.         }
  158.     }
  159.     return( running );
  160. }
  161.  
  162. int OpenProject0Window( void )
  163. {
  164.     struct NewGadget    ng;
  165.     struct Gadget    *g;
  166.     UWORD ww,wh,zh,nwh;
  167.  
  168.     WORD zipsize[]={~0,~0,0,0};
  169.  
  170.     hookentry.h_SubEntry = (ULONG (*)() )password; /* Attempt to get hook working again */
  171.     memset(passfake,PASSCHAR,strlen(password)); /* Show initial string gadget condition */
  172.     passfake[strlen(password)]='\0';
  173.  
  174.     ComputeFont( Project0Width, Project0Height );
  175.  
  176.     ww = ComputeX( Project0Width );
  177.     wh = ComputeY( Project0Height );
  178.  
  179.     if (( winx + ww + OffX + Scr->WBorRight ) > Scr->Width ) winx = Scr->Width - ww;
  180.     if (( winy + wh + OffY + Scr->WBorBottom ) > Scr->Height ) winy = Scr->Height - wh;
  181.  
  182.     zipsize[2]=(WORD)(ww + OffX + Scr->WBorRight);
  183.  
  184.     if (titlebar)
  185.     {
  186.         nwh=(Scr->WBorTop + (Scr->Font->ta_YSize +1));
  187.         zh=wh + OffY + Scr->WBorBottom;
  188.     }
  189.     else
  190.     {
  191.         zh=(Scr->WBorTop + (Scr->Font->ta_YSize +1));
  192.         nwh=wh + OffY + Scr->WBorBottom;
  193.     }
  194.  
  195.     zipsize[3]=(WORD)zh;
  196.  
  197.     if ( ! ( g = CreateContext( &Project0GList )))
  198.         return( 1L );
  199.  
  200. /* */
  201.  
  202.     ng.ng_VisualInfo = VisualInfo;
  203.     ng.ng_TextAttr   = Font;
  204.     ng.ng_LeftEdge    = OffX + ComputeX( 85 );
  205.     ng.ng_TopEdge    = OffY + ComputeY( 17 );
  206.     ng.ng_Width        = ComputeX( 114 );
  207.     ng.ng_Height    = ComputeY( 12 );
  208.     ng.ng_GadgetID    = GD_MYGAD_USER;
  209.     ng.ng_GadgetText= "_Username";
  210.     ng.ng_Flags        = PLACETEXT_LEFT;
  211.     ng.ng_UserData    = (APTR)MYGAD_USERClicked;
  212.  
  213.     Project0Gadgets[GD_MYGAD_USER]=g=    CreateGadget(STRING_KIND,g,&ng,
  214.                                         GTST_String,    username,
  215.                                         GTST_MaxChars,    SMALLSTRING-1,
  216.                                         GT_Underscore,    '_',
  217.                                         TAG_DONE);
  218. /* */
  219.  
  220.     ng.ng_LeftEdge    = OffX + ComputeX( 85 );
  221.     ng.ng_TopEdge    = OffY + ComputeY( 32 );
  222.     ng.ng_Width        = ComputeX( 114 );
  223.     ng.ng_Height    = ComputeY( 12 );
  224.     ng.ng_GadgetID    = GD_MYGAD_PASSWORD;
  225.     ng.ng_GadgetText= "Pass_word";
  226.     ng.ng_Flags        = PLACETEXT_LEFT;
  227.     ng.ng_UserData    = (APTR)MYGAD_PASSWORDClicked;
  228.  
  229.     Project0Gadgets[GD_MYGAD_PASSWORD]=g=    CreateGadget(STRING_KIND,g,&ng,
  230.                                         GTST_String,    passfake,
  231.                                         GTST_EditHook,    &hookentry,
  232.                                         GTST_MaxChars,    SMALLSTRING-1,
  233.                                         GT_Underscore,    '_',
  234.                                         TAG_DONE);
  235.  
  236. /* */
  237.  
  238.     ng.ng_LeftEdge    = OffX + ComputeX( 414 ) - 25;
  239.     ng.ng_TopEdge    = OffY + ComputeY( 32 );
  240.     ng.ng_Width        = ComputeX( 26 );
  241.     ng.ng_Height    = ComputeY( 11 );
  242.     ng.ng_GadgetID    = GD_MYGAD_DELETE;
  243.     ng.ng_GadgetText= "_Delete Messages?";
  244.     ng.ng_Flags        = PLACETEXT_LEFT;
  245.     ng.ng_UserData    = (APTR)MYGAD_DELETEClicked;
  246.  
  247.     Project0Gadgets[GD_MYGAD_DELETE]=g=    CreateGadget(CHECKBOX_KIND,g,&ng,
  248.                                         GTCB_Checked,    delmail,
  249.                                         GTCB_Scaled,    TRUE,
  250.                                         GT_Underscore,    '_',
  251.                                         TAG_END);
  252.  
  253. /* */
  254.  
  255.     ng.ng_LeftEdge    = OffX + ComputeX( 300 );
  256.     ng.ng_TopEdge    = OffY + ComputeY( 2 );
  257.     ng.ng_Width        = ComputeX( 114 );
  258.     ng.ng_Height    = ComputeY( 12 );
  259.     ng.ng_GadgetID    = GD_MYGAD_MAILBOX;
  260.     ng.ng_GadgetText= "Mail _Box";
  261.     ng.ng_Flags        = PLACETEXT_LEFT;
  262.     ng.ng_UserData    = (APTR)MYGAD_MAILBOXClicked;
  263.  
  264.     Project0Gadgets[GD_MYGAD_MAILBOX]=g=    CreateGadget(STRING_KIND,g,&ng,
  265.                                         GTST_String,    mailbox,
  266.                                         GTST_MaxChars,    BIGSTRING-1,
  267.                                         GT_Underscore,    '_',
  268.                                         TAG_DONE);
  269.  
  270. /* */
  271.  
  272.     ng.ng_LeftEdge    = OffX + ComputeX( 329 );
  273.     ng.ng_TopEdge    = OffY + ComputeY( 53 );
  274.     ng.ng_Width        = ComputeX( 83 );
  275.     ng.ng_Height    = ComputeY( 11 );
  276.     ng.ng_GadgetID    = GD_MYGAD_BUTTON;
  277.     ng.ng_GadgetText= "Check _Now";
  278.     ng.ng_Flags        = PLACETEXT_IN;
  279.     ng.ng_UserData    = (APTR)MYGAD_BUTTONClicked;
  280.  
  281.     Project0Gadgets[GD_MYGAD_BUTTON]=g=    CreateGadget(BUTTON_KIND,g,&ng,
  282.                                         GT_Underscore,    '_',
  283.                                         TAG_DONE);
  284.  
  285. /* */
  286.  
  287.     ng.ng_LeftEdge    = OffX + ComputeX( 85 );
  288.     ng.ng_TopEdge    = OffY + ComputeY( 2 );
  289.     ng.ng_Width        = ComputeX( 114 );
  290.     ng.ng_Height    = ComputeY( 12 );
  291.     ng.ng_GadgetID    = GD_MYGAD_HOST;
  292.     ng.ng_GadgetText= "_POP Host";
  293.     ng.ng_Flags        = PLACETEXT_LEFT;
  294.     ng.ng_UserData    = (APTR)MYGAD_HOSTClicked;
  295.  
  296.     Project0Gadgets[GD_MYGAD_HOST]=g=    CreateGadget(STRING_KIND,g,&ng,
  297.                                         GTST_String,    pophost,
  298.                                         GTST_MaxChars,    BIGSTRING-1,
  299.                                         GT_Underscore,    '_',
  300.                                         TAG_DONE);
  301.  
  302. /* */
  303.  
  304.     ng.ng_LeftEdge    = OffX + ComputeX( 202 );
  305.     ng.ng_TopEdge    = OffY + ComputeY( 53 );
  306.     ng.ng_Width        = ComputeX( 39 );
  307.     ng.ng_Height    = ComputeY( 12 );
  308.     ng.ng_GadgetID    = GD_MYGAD_TIME;
  309.     ng.ng_GadgetText= "How _Often";
  310.     ng.ng_Flags        = PLACETEXT_RIGHT;
  311.     ng.ng_UserData    = (APTR)MYGAD_TIMEClicked;
  312.  
  313.     Project0Gadgets[GD_MYGAD_TIME]=g=    CreateGadget(INTEGER_KIND,g,&ng,
  314.                                         GTIN_Number,    timecheck,
  315.                                         GTIN_MaxChars,    3,
  316.                                         GT_Underscore,    '_',
  317.                                         GA_Disabled,    !checkper,
  318.                                         TAG_DONE);
  319.  
  320. /* */
  321.  
  322.     ng.ng_LeftEdge    = OffX + ComputeX( 11 );
  323.     ng.ng_TopEdge    = OffY + ComputeY( 54 );
  324.     ng.ng_Width        = ComputeX( 26 );
  325.     ng.ng_Height    = ComputeY( 11 );
  326.     ng.ng_GadgetID    = GD_MYGAD_CRONCHECK;
  327.     ng.ng_GadgetText= "_Check Periodically";
  328.     ng.ng_Flags        = PLACETEXT_RIGHT;
  329.     ng.ng_UserData    = (APTR)MYGAD_CRONCHECKClicked;
  330.  
  331.     Project0Gadgets[GD_MYGAD_CRONCHECK]=g=    CreateGadget(CHECKBOX_KIND,g,&ng,
  332.                                         GTCB_Scaled,    TRUE,
  333.                                         GTCB_Checked,    checkper,
  334.                                         GT_Underscore,    '_',
  335.                                         TAG_DONE);
  336.  
  337. /* */
  338.  
  339.     ng.ng_LeftEdge    =  OffX + ComputeX( 414 ) - 25;
  340.     ng.ng_TopEdge    = OffY + ComputeY( 17 );
  341.     ng.ng_Width        = ComputeX( 26 );
  342.     ng.ng_Height    = ComputeY( 11 );
  343.     ng.ng_GadgetID    = GD_MYGAD_APPEND;
  344.     ng.ng_GadgetText= "_Append to MailBox?";
  345.     ng.ng_Flags        = PLACETEXT_LEFT;
  346.     ng.ng_UserData    = (APTR)MYGAD_APPENDClicked;
  347.  
  348.     Project0Gadgets[GD_MYGAD_APPEND]=g=    CreateGadget(CHECKBOX_KIND,g,&ng,
  349.                                         GTCB_Scaled,    TRUE,
  350.                                         GT_Underscore,    '_',
  351.                                         GTCB_Checked,    appfile,
  352.                                         TAG_DONE);
  353.  
  354.     if ( ! ( Project0Menus = CreateMenus( Project0NewMenu, TAG_DONE )))
  355.         return( 3L );
  356.  
  357.     LayoutMenus( Project0Menus, VisualInfo, GTMN_NewLookMenus, TRUE, TAG_DONE );
  358.  
  359.     if ( ! ( Project0Wnd = OpenWindowTags( NULL,
  360.                 WA_Left,    (UWORD)winx,
  361.                 WA_Top,        (UWORD)winy,
  362.                 WA_Width,    ww + OffX + Scr->WBorRight,
  363.                 WA_Height,    nwh /*wh + OffY + Scr->WBorBottom*/ ,
  364.                 WA_IDCMP,    STRINGIDCMP|CHECKBOXIDCMP|BUTTONIDCMP|INTEGERIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_CHANGEWINDOW|IDCMP_REFRESHWINDOW,
  365.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH,
  366.                 WA_Gadgets,    Project0GList,
  367.                 WA_Title,    Project0Wdt,
  368.                 WA_PubScreen,    Scr,
  369.                 WA_AutoAdjust,    TRUE,
  370.                 WA_NewLookMenus,TRUE,
  371.                 WA_Activate,    TRUE,
  372.                 WA_Zoom,    zipsize,
  373.                 TAG_DONE )))
  374.     return( 4L );
  375.  
  376.     SetMenuStrip( Project0Wnd, Project0Menus );
  377.     GT_RefreshWindow( Project0Wnd, NULL );
  378.  
  379.     Project0Render();
  380.  
  381.     return( 0L );
  382. }
  383.  
  384. void CloseProject0Window( void )
  385. {
  386.     if ( Project0Menus      ) {
  387.         ClearMenuStrip( Project0Wnd );
  388.         FreeMenus( Project0Menus );
  389.         Project0Menus = NULL;    }
  390.  
  391.     if ( Project0Wnd        ) {
  392.         CloseWindow( Project0Wnd );
  393.         Project0Wnd = NULL;
  394.     }
  395.  
  396.     if ( Project0GList      ) {
  397.         FreeGadgets( Project0GList );
  398.         Project0GList = NULL;
  399.     }
  400. }
  401.  
  402. /* Hook goodies */
  403.  
  404. ULONG __saveds __asm hidepass(register __a0 struct Hook *hook, register __a2 struct SGWork *sgw, register __a1 ULONG *msg)
  405. {
  406.     UBYTE *pass_ptr;
  407.  
  408.     pass_ptr = (STRPTR)hook->h_SubEntry;
  409.  
  410.     sgw->BufferPos = sgw->NumChars; /* Set Cursor position to end of string */
  411.     sgw->Actions |= SGA_REDISPLAY;
  412.  
  413.     if(*msg == SGH_KEY)
  414.     {
  415.         switch (sgw->EditOp)
  416.         {
  417.             case EO_INSERTCHAR:
  418.                 pass_ptr[sgw->NumChars - 1] = sgw->Code;
  419.                 pass_ptr[sgw->NumChars] = '\0';
  420.                 memset(sgw->WorkBuffer,PASSCHAR,strlen(sgw->WorkBuffer)); /* Avoid Intuition rendering */
  421.                 break;
  422.  
  423.             case EO_DELBACKWARD:
  424.                 pass_ptr[sgw->NumChars] = '\0';
  425.                 break;
  426.  
  427.             default:
  428.                 sgw->Actions &= ~SGA_USE;
  429.                 break;
  430.         }
  431.  
  432.         return (~0L);
  433.     }
  434.     else if(*msg == SGH_CLICK)
  435.     {
  436.         return (~0L);
  437.     }
  438.     else
  439.     {
  440.     return (0L);
  441.     }
  442. }
  443.